package com.itheima.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.common.R;
import com.itheima.entity.Category;
import com.itheima.mapper.CategoryMapper;
import com.itheima.service.CategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 菜品及套餐分类 前端控制器
 * </p>
 *
 * @author Guoyh
 * @since 2022-08-19
 */
@Slf4j
@RestController
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;


    @PostMapping
    public R<String> save(@RequestBody Category category){
        categoryService.saveDish(category);
        return R.success("添加成功");
    }

    @GetMapping("/page")
    public R<Page> page(int page, int pageSize){
        Page pageInfo = categoryService.selectByPageAndCondition(page, pageSize);
        return R.success(pageInfo);
    }

    @DeleteMapping
    public R<String> deleteById(long ids){
        categoryService.deleteById(ids);
        return R.success("删除成功");
    }

    @PutMapping
    public R<String> updateById(@RequestBody Category category){
        categoryService.updateCategory(category);
        return R.success("修改成功");
    }

    @GetMapping("/list")
    public R<List<Category>> list(Category category){
        List<Category> categories = categoryService.list(category);
        return R.success(categories);
    }

}

